package policy;

import threadpool.MyRunnable;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-07
 * Time: 23:32
 */
/*
public ThreadPoolExecutor(int corePoolSize,
                          int maximumPoolSize,
                          long keepAliveTime,
                          TimeUnit unit,
                          BlockingQueue<Runnable> workQueue,
                          ThreadFactory threadFactory,
                          RejectedExecutionHandler handler);
                          
    corePoolSize： 核心线程的最大值，不能小于0
    maximumPoolSize：最大线程数，不能小于等于0，maximumPoolSize >= corePoolSize
    keepAliveTime： 空闲线程最大存活时间,不能小于0
    unit： 时间单位
    workQueue： 任务队列，不能为null
    threadFactory： 创建线程工厂,不能为null
    handler： 任务的拒绝策略,不能为null
*/
//演示默认的拒绝策略AbortPolicy，超出任务时丢弃任务并抛出RejectedExecutionException异常。是默认的策略。
public class MyThreadPoolDemo4 {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(
                2,
                5,
                2,
                TimeUnit.HOURS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        //根据参数线程最多有15个，这里测试有16个任务
        for(int i=1;i<=16;i++) {
            threadPoolExecutor.submit(new MyRunnable());
        }
        threadPoolExecutor.shutdown();
    }
    
}
